﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agro.Models;
using System.Web;
using System.Web.Security;
using System.Web.Script.Serialization;

namespace Agro.Library {

    /// <summary>
    /// 当前用户类
    /// </summary>
    public class CurrentUser {

        public CurrentUser() {
            var context = System.Web.HttpContext.Current;
            if (!context.User.Identity.IsAuthenticated) {
                throw new Exception("");
            }
            UserInfo = context.Session["CurrUserInfo"] as T_User;
            if (UserInfo == null) {
                FormsIdentity identity = context.User.Identity as FormsIdentity;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                UserInfo = jss.Deserialize<T_User>(identity.Ticket.UserData);
            }
        }
        public T_User UserInfo { get; private set; }
    }
}
